package tests;

import org.junit.Assert;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import video.MediaPlayer;
import java.io.File;
import java.util.*;

/**
 * @author Heitor Meira de Melo.
 */
public class MediaPlayerTest {
	private MediaPlayer p1;
	private List<String> files;
	private File video;

	@Before
	public void setUp() throws Exception {
		video = new File("Videos/Samples/bailey.flv");
		p1 = new MediaPlayer(null);
	}

	@After
	public void clearUp() {
		p1 = null;
		files = null;
	}

	@Test(expected = Exception.class)
	public void testNullFile() throws Exception {
		p1 = new MediaPlayer(null);
		File nullFile = null;
		p1.createPlayer(nullFile);
	}

	@Test(expected = Exception.class)
	public void testCreateNonexistentFile() throws Exception {
		video = new File("Videos/Samples/Pagodeiro_Macho.mpg");
		p1.createPlayer(video);
	}

	@Test
	public void testPlayVideo() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
	}

	@Test(expected = Exception.class)
	public void testExceptionPlay() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
		p1.play();
	}

	@Test(expected = Exception.class)
	public void testExceptionPause() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
		p1.pause();
	}

	@Test(expected = Exception.class)
	public void testExceptionStop() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
		p1.stop();
	}

	@Test(expected = Exception.class)
	public void testExceptionIsPlaying() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
		p1.isPlaying();
	}

	@Test
	public void testPause() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.pause();
		Assert.assertFalse("Is playing", p1.isPlaying());

		p1.kill();
	}

	@Test
	public void testPlay() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.pause();
		p1.play();
		Assert.assertTrue("Is not playing", p1.isPlaying());

		p1.kill();
	}

	@Test
	public void testStop() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.stop();
		Assert.assertFalse("Is playing", p1.isPlaying());

		p1.kill();
	}

	@Test(expected = Exception.class)
	public void testKill() throws Exception {
		p1.createPlayer(video);
		p1.play();
		Assert.assertTrue(p1.isPlaying());
		p1.kill();
		Assert.assertFalse("Is playing", p1.isPlaying());
	}

}
